package com.wang.lotterysystem.dao.mapper;

import com.wang.lotterysystem.dao.dataobject.activity.ActivityPrizeDO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ActivityPrizeMapper {
    @Insert("<script>" +
            "insert into activity_prize (activity_id, prize_id, prize_tiers, prize_amount, status) VALUE " +
            "<foreach collection = 'activityPrizeDOList' item = 'item' index = 'index' separator = ','>" +
            "(#{item.activityId},#{item.prizeId},#{item.prizeTiers},#{item.prizeAmount},#{item.status})" +
            "</foreach>" +
            "</script>")
    @Options(useGeneratedKeys = true,keyColumn = "id",keyProperty = "id")
    int batchInsert(List<ActivityPrizeDO> activityPrizeDOList);

    @Select("select id, gmt_create, gmt_modified, activity_id, prize_id, prize_amount, prize_tiers, status" +
            " from activity_prize " +
            "where activity_id = #{activityId} and prize_id = #{prizeId}")
    ActivityPrizeDO selectByActivityAndPrizeId(Long activityId, Long prizeId);

    @Update("update activity_prize set status = #{prizeTargetStatus} " +
            "where activity_id = #{activityId} and prize_id = #{prizeId}")
    void updateStatus(Long activityId,Long prizeId,String prizeTargetStatus);

    @Select("select count(1) from activity_prize " +
            "where activity_id = #{activityId} and status = #{status}")
    int countRunningPrizeByActivityId(Long activityId,String status);

    @Select("select * from activity_prize " +
            "where activity_id = #{activityId}")
    List<ActivityPrizeDO> selectByActivityId(Long activityId);
}